package com.google.common.util.service.life.practice;

import com.google.common.util.concurrent.AbstractScheduledService;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * User: wujun
 * Date: 2014/7/29
 */
public class MyScheduledService extends AbstractScheduledService {
    private AtomicInteger num = new AtomicInteger();
    @Override
    protected void runOneIteration() throws Exception {
        System.out.println(num.incrementAndGet());
    }

    @Override
    protected void startUp() throws Exception {
        System.out.println("startUp");
    }

    @Override
    protected void shutDown() throws Exception {
        System.out.println("shutDown");
    }

    @Override
    protected Scheduler scheduler() {
        return Scheduler.newFixedRateSchedule(0, 1, TimeUnit.SECONDS);
    }
}
